package com.itheima;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 演示Collections工具的使用
 */
public class CollectionsDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "王五", "赵六");
        list.forEach(System.out::println);
        System.out.println("----------------");
        //打乱集合的顺序
        Collections.shuffle(list);
        list.forEach(System.out::println);

        test1();
    }
    public static void test1(){
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5);
        //按照倒序排序
        Collections.sort(list, (o1, o2) -> o2 - o1);
        list.forEach(System.out::println);
        System.out.println("----------------");

        //让学生实现Comparable接口，按照年龄排序
        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三", 18));
        list1.add(new Student("李四", 19));
        list1.add(new Student("王五", 17));
        list1.add(new Student("赵六", 16));
        Collections.sort(list1);
        list1.forEach(System.out::println);




    }


}
